Don't lock overrides if we're updating them
authorAlex Crichton <alex@alexcrichton.com>
Sun, 5 Jun 2016 07:19:55 +0000 (00:19 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 5 Jun 2016 07:20:21 +0000 (00:20 -0700)
There was already a function for this, `keep`, it was just forgotten to be
called.

Closes #2766

src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/resolve.rs
tests/overrides.rs

index 9b96abd75be534f9a23650467fd184cc0579685c..14c3322c5a8aeff700012619ef85519d019ce4f6 100644 (file)
@@ -37,10 +37,8 @@ pub fn update_lockfile(manifest_path: &Path,
     let package = try!(Package::for_path(manifest_path, opts.config));
 
     let previous_resolve = match try!(ops::load_pkg_lockfile(&package, opts.config)) {
-       Some(resolve) => resolve,
-       None => {
-            return generate_lockfile(manifest_path, opts.config);
-       }
+        Some(resolve) => resolve,
+        None => return generate_lockfile(manifest_path, opts.config),
     };
     let mut registry = PackageRegistry::new(opts.config);
     let mut to_avoid = HashSet::new();
index adc3e6ae435c7b0b2bdf06ba6a896b88ac1fb251..5f745465598f471e026218549e085d04c315b12d 100644 (file)
@@ -105,7 +105,9 @@ pub fn resolve_with_previous<'a>(registry: &mut PackageRegistry,
             let replace = package.manifest().replace();
             let replace = replace.iter().map(|&(ref spec, ref dep)| {
                 for (key, val) in r.replacements().iter() {
-                    if spec.matches(key) && dep.matches_id(val) {
+                    if spec.matches(key) &&
+                       dep.matches_id(val) &&
+                       keep(&val, to_avoid, &to_avoid_sources) {
                         return (spec.clone(), dep.clone().lock_to(val))
                     }
                 }
index 2f87638f0bb7a853c5c264e4383aa5747739258a..b4a385fb8f5357d6ce6cfa70766f02342629b501 100644 (file)
@@ -578,3 +578,42 @@ Please re-run this command with [..]
   [..]#foo:0.1.0
 "));
 }
+
+#[test]
+fn update() {
+    Package::new("foo", "0.1.0").publish();
+
+    let foo = git::repo(&paths::root().join("override"))
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("src/lib.rs", "pub fn foo() {}");
+    foo.build();
+
+    let p = project("local")
+        .file("Cargo.toml", &format!(r#"
+            [package]
+            name = "local"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            foo = "0.1.0"
+
+            [replace]
+            "foo:0.1.0" = {{ git = '{0}' }}
+        "#, foo.url()))
+        .file("src/lib.rs", "");
+
+    assert_that(p.cargo_process("generate-lockfile"),
+                execs().with_status(0));
+    assert_that(p.cargo("update"),
+                execs().with_status(0)
+                       .with_stderr("\
+[UPDATING] registry `[..]`
+[UPDATING] git repository `[..]`
+"));
+}